%option noyywrap nodefault yylineno

%{
#include "expr.h"
#include "parser.hpp"

#define YY_DECL extern "C" int yylex(void)

//#define YYTRACE(x...) printf(x)
#define YYTRACE(x...) 
%}

%%
[ \t\r]                   {}
"\n"                    {/*YYTRACE("EOL");return EOL;*/}
"int"                   {YYTRACE("INT");yylval.ival = INT;return INT;}
"string"                {YYTRACE("STRTYPE");yylval.ival = STRTYPE;return STRTYPE;}
"func"                {YYTRACE("STRTYPE");yylval.ival = FUNCTYPE;return FUNCTYPE;}
"while"               {YYTRACE("WHILE");yylval.ival = WHILE;return WHILE;}
"if"                  {YYTRACE("IF");yylval.ival = IF;return IF;}
"else"                {YYTRACE("ELSE");yylval.ival = ELSE;return ELSE;}
"end"                 {YYTRACE("END");yylval.ival = END;return END;}
[a-zA-Z][a-zA-Z0-9_]*   {YYTRACE("ID");yylval.str = strdup(yytext);return ID;}
[0-9]+                  {YYTRACE("NUMBER(%d)",atoi(yytext));yylval.str = strdup(yytext);return NUMBER;}
\"[^"]*\"               {YYTRACE("STRING(%s)",yytext);yylval.str = strdup(yytext);return STRING;}

"+" |
"-" |
"*" |
"/" |
"," |
";" |
":" |
"(" |
")" |
"[" |
"]" |
"{" |
"}" |
"<" |
">" |
"="                     {YYTRACE("%c",yytext[0]);return yytext[0];}
 
"=="                    {return EQ;}
"<="                    {return LE;}
">="                    {return GE;}
"!="                    {return NE;}
.                       {YYTRACE("unknown token %s\n",yytext);}
%%
